﻿@Html.DevExpress().GridView(
            settings =>
            {
                settings.Name = "gvEditing";
                settings.KeyFieldName = "FItemNo";
                settings.CallbackRouteValues = new { Controller = "OfficeItemCount", Action = "OfficeItemCountListPartial" };
                settings.Width =System.Web.UI.WebControls.Unit.Percentage(100);
                               
                settings.Columns.Add(c =>
                {
                    c.FieldName = "FItemClsName";
                    c.Caption = "用品类别";
                    c.Width = 260;
                    c.GroupIndex = 0;
                    c.SortOrder = DevExpress.Data.ColumnSortOrder.Ascending;
                });
                
                settings.Columns.Add(column =>
                {
                    column.Caption = "用品名称";
                    column.FieldName = "FItemName";
                    column.CellStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
                });

                settings.Columns.Add(column =>
                {
                    column.Caption = "paixu";
                    column.FieldName = "Feq";
                    column.CellStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
                    column.Visible = false;
                    column.SortOrder = DevExpress.Data.ColumnSortOrder.Ascending;
                });

                

                settings.Columns.Add(column =>
                {
                    column.Caption = "规格";
                    column.FieldName = "FItemSpec";
                    column.Width=40;
                    column.CellStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
                });

                settings.Columns.Add(column =>
                {
                    column.Caption = "总采购数";
                    column.FieldName = "qty1";
                    column.CellStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Right;
                });

                settings.Columns.Add(column =>
                {
                    column.Caption = "总采购金额";
                    column.FieldName = "amount1";
                    column.CellStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Right;
                });

                settings.Columns.Add(column =>
                {
                    column.Caption = "总申请数";
                    column.FieldName = "qty2";
                    column.CellStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Right;
                });

                settings.Columns.Add(column =>
                {
                    column.Caption = "总实际领用领用数";
                    column.FieldName = "FApplyQtyDec";
                    column.CellStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Right;
                });
                settings.Columns.Add(column =>
                {
                    column.Caption = "总领用金额";
                    column.FieldName = "amount2";
                    column.CellStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Right;
                });
                settings.Columns.Add(column =>
                {
                    column.Caption = "库存";
                    column.FieldName = "FQty";
                    column.CellStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Right;
                                       
                });

                settings.TotalSummary.Add(DevExpress.Data.SummaryItemType.Sum, "FItemName").DisplayFormat = "合计";
                settings.TotalSummary.Add(DevExpress.Data.SummaryItemType.Custom, "qty1").DisplayFormat = "{0}" + ViewData["sum2"].ToString();
                settings.TotalSummary.Add(DevExpress.Data.SummaryItemType.Custom, "amount1").DisplayFormat ="{0}"+ ViewData["sum3"].ToString();
                settings.TotalSummary.Add(DevExpress.Data.SummaryItemType.Custom, "qty2").DisplayFormat = "{0}" + ViewData["sum4"].ToString(); ;
                settings.TotalSummary.Add(DevExpress.Data.SummaryItemType.Custom, "FApplyQtyDec").DisplayFormat = "{0}" + ViewData["sum5"].ToString();
                settings.TotalSummary.Add(DevExpress.Data.SummaryItemType.Custom, "amount2").DisplayFormat = "{0}" + ViewData["sum6"].ToString();
                settings.TotalSummary.Add(DevExpress.Data.SummaryItemType.Custom, "FQty").DisplayFormat = "{0}" + ViewData["sum1"].ToString();
                
                               
                settings.Settings.ShowFooter = true;
                //settings.SettingsBehavior.AllowSort = false;
                //settings.SettingsBehavior.AllowDragDrop = false;
                settings.SettingsBehavior.AllowSelectByRowClick = false;
                settings.SettingsLoadingPanel.Text = "数据读取中...";
                //settings.SettingsBehavior.AllowClientEventsOnLoad = false;
                //settings.SettingsBehavior.AllowFocusedRow = true;
                settings.ClientSideEvents.BeginCallback = "function(s,e){OnBeginCallback(s,e)}";
                //settings.ClientSideEvents.RowDblClick = "function(s,e){RowDblClick(s,e)}";

                settings.SettingsPager.Visible = false;

                settings.SettingsPager.Mode = GridViewPagerMode.ShowAllRecords;
                
                
                settings.CommandColumn.SetHeaderTemplateContent(c =>
                {
                    Html.DevExpress().CheckBox(settingsCheckBox =>
                    {
                        settingsCheckBox.Name = "cbSelectAll";
                        settingsCheckBox.Properties.ClientSideEvents.CheckedChanged = string.Format("function(s, e) {{ if(s.GetChecked()) {0}.SelectAllRowsOnPage(); else {0}.UnselectAllRowsOnPage(); }}", settings.Name);

                        if (c.Grid.VisibleRowCount == 0)
                        {
                            settingsCheckBox.Enabled = false;

                        }
                        else
                        {
                            settingsCheckBox.Checked = c.Grid.VisibleRowCount == c.Grid.Selection.Count;
                        }


                    }).Render();
                });
                                
                
                settings.PageIndexChanged = (sender, e) =>
                {
                    ASPxGridView grid = (ASPxGridView)sender;
                    grid.Selection.UnselectAll();
                };

                settings.DataBinding = (sender, e) =>
                {
                    ASPxGridView grid = (ASPxGridView)sender;
                    for (int i = 0; i < grid.AllColumns.Count; i++)
                    {
                        if (grid.AllColumns[i].CellStyle.HorizontalAlign == System.Web.UI.WebControls.HorizontalAlign.NotSet)
                        {
                            grid.AllColumns[i].CellStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
                        }
                        if (grid.AllColumns[i].HeaderStyle.HorizontalAlign == System.Web.UI.WebControls.HorizontalAlign.NotSet)
                        {
                            grid.AllColumns[i].HeaderStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
                        }
                    }
                };
                
            }).Bind(Model).GetHtml()

